package com.chinaisafe.user.dto;

import com.chinaisafe.user.entity.SysLoginLog;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.io.Serializable;

/**
 * SysLoginLogDTO
 * Description：登录日志数据传输对象
 *
 * @author xuefu.shu
 * @date  2024-07-12 09:55:54
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@Schema(name = "SysLoginLogDTO", description = "登录日志数据传输对象")
public class SysLoginLogDTO implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "主键id")
    private Long id;

    @Schema(description = "用户id")
    private Long sysUserId;

    @Schema(description = "登录账号")
    private String loginName;

    @Schema(description = "手机号")
    private String mobile;

    @Schema(description = "微信openid")
    private String wxOpenid;

    @Schema(description = "认证方式")
    private String authType;

    @Schema(description = "登录ip")
    private String loginIp;

    @Schema(description = "登录地点")
    private String loginAddress;

    @Schema(description = "客户端类型")
    private String client;

    @Schema(description = "登录状态(成功/失败)")
    private Boolean status;

    @Schema(description = "访问时间")
    private LocalDateTime loginTime;


    /**
     * 将实体类转换为数据传输对象
     * @param entity 实体对象
     * @return SysLoginLogDTO 数据传输对象
     * @author xuefu.shu
     * @date 2024-07-12 09:55:54
     */
    public static SysLoginLogDTO convertFromEntity(SysLoginLog entity) {
        SysLoginLogDTO dto = new SysLoginLogDTO();
        dto.id = entity.getId();
        // 给对应的字段赋值 可根据实际业务删减
        dto.sysUserId = entity.getSysUserId();
        dto.loginName = entity.getLoginName();
        dto.mobile = entity.getMobile();
        dto.wxOpenid = entity.getWxOpenid();
        dto.authType = entity.getAuthType();
        dto.loginIp = entity.getLoginIp();
        dto.loginAddress = entity.getLoginAddress();
        dto.client = entity.getClient();
        dto.status = entity.getStatus();
        dto.loginTime = entity.getLoginTime();
        return dto;
    }
}
